package awl;

import static org.junit.Assert.assertFalse;
import awl.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.RobotState;
import robocode.control.events.BattleCompletedEvent;

/**
 * Test Xinetd has hit a single wall during the battle.
 * Xinetd should move along parallel to the four walls.
 * 
 * @author Alan Lee
 */
public class TestXinetdHitWall extends RobotTestBed {
  /** True if the robot hit a wall during the test case. */
  boolean hitWall = false;

  /**
   * Specifies that SittingDuck and Xinetd are to be matched up in this test case.
   * 
   * @return A comma-delimited list of robots in this match
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,awl.Xinetd";
  }
  
  /**
   * This test runs for a round.
   * 
   * @return The number of rounds in this test 
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * After each turn, check to see if Xinetd hit wall.
   * If so, set flag.
   * 
   * @param event Information about the current state of the battle
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    RobotState myrobo = RobotState.ACTIVE;
    if (hitWall = myrobo.isHitWall()) {
      hitWall = true;
    }
  }
  
  /**
   * Asserts that Xinetd running along parallel to the four walls.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertFalse("Hit Wall", hitWall);
  }
  
  /**
   * Returns false, thus making the robots always start at a random position each time.
   * 
   * @return False if the battle will not be deterministic, true otherwise
   */
  @Override
  public boolean isDeterministic() {
    return false;
  }
  
}
